
package com.group8.ui;

import java.awt.Color;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;

public class SettingsPanel extends Menu{
	
	JLabel title;
	JLabel musicL;
	JLabel fxL;
	JCheckBox soundC;
	JCheckBox fxC;
	JButton back;
	
	public SettingsPanel(){
		setPreferredSize(new Dimension(800,660));
		setLayout(null);
		setBackground(Color.WHITE);
		
		CheckBoxListener cl = new CheckBoxListener();
		
		back = new JButton();
		Image img = new ImageIcon("assets/main_menu/back.png").getImage();
		back.setIcon(new ImageIcon(img));
		back.setRolloverEnabled(false);
		back.setBounds(500,500,93,40);
		back.addActionListener(cl);
		
		title = new JLabel("Settings");
		title.setBounds(300,90,300,100);
		title .setForeground(Color.RED);
		title.setFont(new Font("nfont", Font.PLAIN, 50));
		
		musicL = new JLabel("Music");
		musicL.setFont(new Font("nfont", Font.PLAIN, 40));
		musicL.setForeground(Color.YELLOW);
		musicL.setBounds(250,220,300,100);
		
		fxL = new JLabel("FX Sound");
		fxL.setFont(new Font("nfont", Font.PLAIN, 40));
		fxL.setBounds(250,310,300,100);
		fxL.setForeground(Color.BLUE);
		
		soundC = new JCheckBox();
		soundC.setBounds(460,265,20,20);
		soundC.addActionListener(cl);
		
		fxC = new JCheckBox();
		fxC.setBounds(460,355,20,20);
		fxC.addActionListener(cl);
		
		
		add(title);
		add(musicL);
		add(fxL);
		add(soundC);
		add(fxC);
		add(back);
	}
	
	private class CheckBoxListener extends MenuActionListener{
		
		public void actionPerformed(ActionEvent e) {
			boolean sound = true, fx = true;
			if(e.getSource() == soundC)
				if(soundC.isSelected())
					sound = true;
				else
					sound = false;
			else if(e.getSource() == fxC)
				if(fxC.isSelected())
					fx = true;
				else
					fx = false;
			if(e.getSource() == back){
				switchPanels(getMain());
				System.out.println("Back clicked");
			}
			else
				changeSoundState(sound,fx);
			
		}
		
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Image img = new ImageIcon("assets/settings_background.jpg").getImage();
		g.drawImage(img, 0, 0, null);
	}
}

